package com.exmaple.listviewswipeleftdemo;


import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends FragmentActivity {
    private RecyclerAdapter mAdapter;
    private List<UserBean> list = new ArrayList<>();//观看历史记录
    private RecyclerView recyclerView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        recyclerView = new SwipeMenuRecyclerView(this);
        setContentView(recyclerView);
        initView();
        initData();
    }

    public void initView() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(MainActivity.this);
        recyclerView.setLayoutManager(linearLayoutManager);
        DividerItemDecoration dividerItemDecoration =
                new DividerItemDecoration(this, DividerItemDecoration.VERTICAL);
        recyclerView.addItemDecoration(dividerItemDecoration);
        mAdapter = new RecyclerAdapter(MainActivity.this, list, new RecyclerAdapter.ItemTouchListener() {
            @Override
            public void onItemClick(int position) {
                Toast.makeText(MainActivity.this, String.format("%d", position), Toast.LENGTH_LONG).show();
                mAdapter.notifyDataSetChanged();
            }
        });
        recyclerView.setAdapter(mAdapter);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
    }

    public void initData() {
        UserBean bean = new UserBean();
        bean.setName("aoe");
        bean.setType(0);
        list.add(bean);
        UserBean bean2 = new UserBean();
        bean2.setName("abc");
        bean2.setType(1);
        list.add(bean2);
        mAdapter.addData(list);
    }

}
